<?php

declare (strict_types=1);

namespace App\Model\GuildManage;

use App\Model\Guild\GuildBase;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Model;
use Hyperf\Database\Model\SoftDeletes;

/**
 */
class GuildAccount extends GuildBase
{
    use SoftDeletes;

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'guild_account';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [];

    const STATUS_AUDIT = 0;

    const STATUS_PASS = 1;

    const STATUS_NO_PASS = 2;

    /**
     * 根据userId获取数据
     * @param $userId
     * @return int
     */
    public function getCountByUserId($userId): int
    {
        return $this->where('user_id', $userId)->count() ?? 0;
    }

    /**
     * 返回默认值
     * @param $userId
     * @return Builder|Model|object|null
     */
    public function getDefaultAccountByUserId($userId)
    {
        return $this->where('user_id', $userId)->where('default', 1)->first();
    }
}